import { toHump } from '@/util/CommonUtil'
import CFrame from '@/layout/CFrame/CFrame'

interface IRouterMapItem {
  elementTemp: any
}

const routerMap: Record<string, IRouterMapItem> = {} // 路由 map

// 自动获取路由 map
const fileObj: Record<string, { [key: string]: any }> = import.meta.globEager(
  '/src/page/**/*.tsx'
)
Object.keys(fileObj).forEach((item: string) => {
  if (
    item.includes('Modal.tsx') ||
    item.includes('Drawer.tsx') ||
    item.includes('/components/') ||
    item.includes('Columns.tsx') ||
    item.includes('FormItem.tsx')
  )
    return // 不要 Modal.tsx，Drawer.tsx，FormItem.tsx 结尾的文件，以及 components文件夹下面的文件
  const fileName = toHump(
    item.split('/src/page/')[1].split('.tsx')[0].replaceAll('/', '_')
  ) // 例如：userLoginLogin
  routerMap[fileName] = {
    elementTemp: fileObj[item].default,
  }
})

// 手动设置路由 map
routerMap['frame'] = {
  elementTemp: CFrame,
}

export const routerMapKeyList = Object.keys(routerMap)

export default routerMap
